
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Administrator
 */
public class SocketServer {
    public static void main(String[] args) throws IOException{
        while(true){
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(10001);
        } catch (IOException e) {
            System.err.println("Could not listen on port: 10001.");
            System.exit(1);
        }

        Socket clientSocket = null;
        try {
            clientSocket = serverSocket.accept();
        } catch (IOException e) {
            System.err.println("Accept failed.");
            System.exit(1);
        }

        PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
        InputStream in =clientSocket.getInputStream();
        String inputLine;

        byte[] cbuf = new byte[26];
        if ( in.read(cbuf) != -1) {        
            for(byte d:cbuf){
                System.out.print((byte)d);
                System.out.print(" ");
            }
            
        }
        int weight=0;
        weight = weight|(cbuf[16]&0xff);
        weight=weight<<8;
        weight = weight|(cbuf[17]&0xff);
        weight=weight<<8;
        weight = weight|(cbuf[18]&0xff);
        
        System.out.println(weight+"kg");
        
        
        out.write("abc");
        System.out.println();
        out.close();
        in.close();
        clientSocket.close();
        serverSocket.close();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                
            }
        }
    }
    
    
}
